package com.example.evaluationserver.controller;

import com.example.evaluationserver.params.EvaluationParams;
import com.example.evaluationserver.params.PageEvaluationParams;
import com.example.evaluationserver.service.EvaluationService;
import com.example.evaluationserver.vo.EvaluationNumVO;
import com.example.evaluationserver.vo.EvaluationVO;
import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.vo.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/evaluation-server")
@Api(tags = "评价接口")
public class EaluationController {
    @Autowired
    private EvaluationService evaluationService;

    @ApiOperation(value = "获取评价")
    @PostMapping(value = "/page")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<EvaluationVO>> pageEvaluation(@RequestBody PageEvaluationParams pageEvaluationParams) {
        return new Result(evaluationService.pageEvaluation(pageEvaluationParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取各评价数量")
    @GetMapping(value = "/num")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<EvaluationNumVO> getEvaluationNum(@RequestParam String userId) {
        return new Result(evaluationService.getEvaluationNum(userId), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取评价")
    @PostMapping(value = "/pagePost")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<EvaluationVO>> pageEvaluationPost(@RequestBody PageEvaluationParams pageEvaluationParams) {
        return new Result(evaluationService.pageEvaluationPost(pageEvaluationParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取各评价数量")
    @GetMapping(value = "/numPost")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<EvaluationNumVO> getEvaluationNumPost(@RequestParam String userId) {
        return new Result(evaluationService.getEvaluationNumPost(userId), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "删除评价")
    @PostMapping(value = "/delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteEvaluation(@RequestParam String id) {
        evaluationService.deleteEvaluation(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "修改评价")
    @PostMapping(value = "/update")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateEvaluation(@RequestBody EvaluationParams evaluationParams) {
        return new Result(evaluationService.updateEvaluation(evaluationParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "新增评价")
    @PutMapping(value = "/insert")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertEvaluation(@RequestBody EvaluationParams evaluationParams) {
        return evaluationService.insertEvaluation(evaluationParams);
    }
}
